home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Puppeteer1.1 / Source / RemoteView.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  138 lines

  1. /*
  2.  * Puppeteer 1.1
  3.  *
  4.  * Copyright (c) 1994 Primitive Software Ltd.  All rights reserved.
  5.  *
  6.  * Author: Dave Griffiths <dave@prim.demon.co.uk>
  7.  */
  8.  
  9. #import "RemoteView.h"
  10. #import "Puppeteer.h"
  11. #import "WindowInfo.h"
  12. #import "Controller.h"
  13.  
  14. extern id puppet;
  15.  
  16. @implementation RemoteView
  17.  
  18. - restoreCursor:(NXEvent *)theEvent
  19. /*
  20.  * Restore the mouse position.
  21.  */
  22. {
  23.     NXPoint point;
  24.     
  25.     point = theEvent->location;
  26.     [self convertPoint:&point fromView:NULL];
  27.     [self lockFocus];
  28.     PSsetmouse(point.x, point.y);
  29.     NXPing();
  30.     [self unlockFocus];
  31.  
  32.     return self;
  33. }
  34.  
  35. - mouseDownOrDragged:(NXEvent *)theEvent
  36. {
  37.     NXPoint point = theEvent->location;
  38.     int selectedWindow = [[NXApp delegate] selectedWindow];
  39.  
  40.     [self convertPoint:&point fromView:NULL];
  41.     [puppet postMouseEvent:theEvent->type window:selectedWindow 
  42.         flags:theEvent->flags x:point.x y:point.y 
  43.         click:theEvent->data.mouse.click];
  44.     [puppet ping];
  45.  
  46.     [self restoreCursor:theEvent];
  47.  
  48.     return self;
  49. }
  50.  
  51. - mouseDown:(NXEvent *)theEvent
  52. {
  53.     NXPoint point = theEvent->location;
  54.     NXRect wframe;
  55.     int winNum;
  56.     
  57.     if ([[NXApp delegate] printMouseClicks]) {
  58.         [self convertPoint:&point fromView:NULL];
  59.         [puppetWindow getFrame:&wframe];
  60.         winNum = [puppetWindow localWindowNumber];
  61.         printf("Puppeteer: mouse down in window %d (w = %f, h = %f) at x = %f, y = %f\n", winNum, wframe.size.width, wframe.size.height, point.x, point.y);
  62.     }
  63.     
  64.     [window addToEventMask:NX_MOUSEDRAGGEDMASK];
  65.     
  66.     [puppet postActivate:YES];
  67.     
  68.     [self mouseDownOrDragged:theEvent];
  69.     
  70.     return [super mouseDown:theEvent];
  71. }
  72.  
  73. - mouseDragged:(NXEvent *)theEvent
  74. {
  75.     [self mouseDownOrDragged:theEvent];
  76.  
  77.     return [super mouseDragged:theEvent];
  78. }
  79.  
  80. - mouseUp:(NXEvent *)theEvent
  81. {
  82.     NXPoint point = theEvent->location;
  83.     int selectedWindow = [[NXApp delegate] selectedWindow];
  84.     NXRect wframe;
  85.     int winNum;
  86.  
  87.     [self convertPoint:&point fromView:NULL];
  88.     if ([[NXApp delegate] printMouseClicks]) {
  89.         [puppetWindow getFrame:&wframe];
  90.         winNum = [puppetWindow localWindowNumber];
  91.         printf("Puppeteer: mouse up in window %d (w = %f, h = %f) at x = %f, y = %f\n", winNum, wframe.size.width, wframe.size.height, point.x, point.y);
  92.     }
  93.     
  94.     [puppet postMouseEvent:theEvent->type window:selectedWindow 
  95.         flags:theEvent->flags x:point.x y:point.y
  96.         click:theEvent->data.mouse.click];
  97.     [puppet postActivate:NO];
  98.     [puppet ping];
  99.     [puppetWindow copyWindowToImage:image];
  100.     [NXApp activateSelf:YES];
  101.     [self display];
  102.     [[NXApp delegate] reloadPopupList];
  103.     
  104.     [self restoreCursor:theEvent];
  105.             
  106.     return [super mouseUp:theEvent];
  107. }
  108.  
  109. - setWindow:theWindow
  110. {
  111.     puppetWindow = theWindow;
  112.     
  113.     [self setImage:[puppetWindow windowImage]];
  114.     
  115.     return self;
  116. }
  117.  
  118. - setImage:theImage
  119. {
  120.     NXSize theSize;
  121.     
  122.     image = theImage;
  123.     [image getSize:&theSize];
  124.     [self sizeTo:theSize.width:theSize.height];
  125.     [self display];
  126.     
  127.     return self;
  128. }
  129.  
  130. - drawSelf:(const NXRect *)rects :(int)count
  131. {
  132.     [image composite:NX_COPY toPoint:&(bounds.origin)];
  133.     
  134.     return self;
  135. }
  136.  
  137. @end
  138.